package db9;

import java.util.Scanner;

public class MailTest {
    public static void main(String[] args) {
        MailTest();
    }
    public static void MailTest(){
        Scanner sc =new Scanner(System.in);
        System.out.println("邮箱：");
        String mail =sc.nextLine();
        if (mail.indexOf("@")==-1){
            System.out.println("邮箱地址不包含@");
        }if (mail.indexOf("@")==-1){
            System.out.println("邮箱地址不包括.");
        }
        int a=0 ;
        for (int i = 0; i < mail.length(); i++) {
            if (mail.charAt(i)=='@'){
                a++;
            }
        }if (a>1){
            System.out.println("邮箱有多余的@");
        }
        int b= 0;
        for (int i = 0; i < mail.length(); i++) {
            if (mail.charAt(i)=='.'){
                b++;
            }
        }if (b>1){
            System.out.println("邮箱中有多余的.");
        }
        int index =mail.indexOf('@');
        int index1 = mail.indexOf('.');
        if (index1<=index){
            System.out.println("邮箱地址中.出现在@前面");
        }
        String R = "\\w + @ \\w +\\.\\w{2,3} ";
        if(!(mail.matches(R))){
            System.out.println("用户名里有其他字符");
        }
    }
}
